//
//  SignatureTableViewCell.m
//  Today
//
//  Created by fanfan on 15/5/22.
//  Copyright (c) 2015年 fanfan. All rights reserved.
//

#import "SignatureTableViewCell.h"

@implementation SignatureTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createMycell];
    }
    return self;
}
//创建自己的cell视图
-(void)createMycell
{
    
    self.TitleLable = [[UILabel alloc]init];
    [self.contentView addSubview:self.TitleLable];
    [self.TitleLable release];
    
    self.PicImage = [[UIImageView alloc]init];
    [self.contentView addSubview:self.PicImage];
    [self.PicImage release];
    
    self.TimeStrLable = [[UILabel alloc]init];
    [self.contentView addSubview:self.TimeStrLable];
    [self.TimeStrLable release];
    
    self.ShareICon = [[UIImageView alloc]init];
    [self.contentView addSubview:self.ShareICon];
    [self.ShareICon release];
    
    self.SharePressBut = [[UIButton alloc]init];
    [self.contentView addSubview:self.SharePressBut];
    [self.SharePressBut release];
    
    self.CollectinoIcon = [[UIImageView alloc]init];
    [self.contentView addSubview:self.CollectinoIcon];
    [self.CollectinoIcon release];
    
    self.CollectionPressbut = [[UIButton alloc]init];
    [self.contentView addSubview:self.CollectionPressbut];
    [self.CollectionPressbut release];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    self.TitleLable.frame = CGRectMake(5, 0, 375, 50);
    self.TitleLable.textColor = [UIColor blackColor];
    self.TitleLable.numberOfLines = 3;
    [self.TitleLable sizeToFit];
    self.PicImage.frame = CGRectMake(8, 60, 360,200);
    self.PicImage.contentMode = UIViewContentModeScaleAspectFit;
    self.TimeStrLable.frame = CGRectMake(10, 270, 150, 20);
    self.ShareICon.frame = CGRectMake(200, 260, 30, 30);
    self.SharePressBut.frame = CGRectMake(225, 260, 50, 30);
    [self.SharePressBut setTitle:@"分享" forState:UIControlStateNormal];
    [self.SharePressBut addTarget:self action:@selector(SharePress:) forControlEvents:UIControlEventTouchUpInside];
    [self.SharePressBut setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    self.CollectinoIcon.frame = CGRectMake(285, 260, 30, 30);
    self.CollectionPressbut.frame = CGRectMake(310, 260, 50, 30);
    [self.CollectionPressbut setTitle:@"收藏" forState:UIControlStateNormal];
    [self.CollectionPressbut addTarget:self action:@selector(CollectionContent:) forControlEvents:UIControlEventTouchUpInside];
    [self.CollectionPressbut setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}
- (void)SharePress:(id)sender
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button = (UIButton *)sender;
    [self.Mydeleget shareContent:(button.tag - 1000)];
}
-(void)CollectionContent:(UIButton *)collectionbutton
{
    SignatureData *data = [[SignatureData alloc]init];
    [data createSignatureTable];
    BOOL isexists = [data isExists:_Model.title];
    if (!isexists) {
        SIAlertView *alt = [[SIAlertView alloc]initWithTitle:@"提示" andMessage:@"亲你已经收藏过了"];
        [alt  addButtonWithTitle:@"确定" type:SIAlertViewButtonTypeDefault handler:^(SIAlertView *alertView) {
        }];
        [alt show];
    }else{
        
        [data insertSignatureTable:_Model];
    }
    
}

//重写model方法
-(void)setModel:(SignatureModel *)Model
{
    _Model = Model;
    self.TitleLable.text = Model.title;
    NSURL *url = [NSURL URLWithString:Model.pic];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *image = [UIImage imageWithData:data];
    self.PicImage.image = image;
    self.TimeStrLable.text = Model.timeStr;
    self.ShareICon.image = [UIImage imageNamed:@"star_faved@2x"];
    self.CollectinoIcon.image = [UIImage imageNamed:@"iconfont-fenxiang"];
    
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
